// 封装 mysql 模块并导出函数
module.exports = (sql,values = null) => {
    // 1. 加载模块
    const mysql = require('mysql');
    const conn = mysql.createConnection({
        host: 'localhost',
        user: 'root',
        password: 'root',
        database: 'xdd'
    });
    return new Promise((resolve, reject) => {
        // 异步代码
        conn.connect();
        conn.query(sql,values,(err,result) => {
            err ? reject(err): resolve(result);
        });
        conn.end();
    }).catch(e => {
        console.log('=================================');
        console.log('错误的描述：' + e.sqlMessage);
        console.log('错误的SQL：' + e.sql)
        console.log('=================================');
    });
};